package com.second.market.service.impl;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.second.common.pojo.RR;
import com.second.market.mapper.CustomerMapper;
import com.second.market.pojo.entity.Advertise;
import com.second.market.pojo.entity.TbCustomerIssues;
import com.second.market.pojo.vo.CustomerVo;
import com.second.market.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: clms-second
 * @description: 客户问答实现类
 * @author: 邓衡
 * @create: 2021-07-24 15:13
 **/
@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public RR finAllcustomerByPage(Integer currentPage, Integer pageSize, CustomerVo customerVo) {
        Page<TbCustomerIssues> page=new Page<>(currentPage,pageSize);
        QueryWrapper<TbCustomerIssues> wrapper=new QueryWrapper<>();

        if (StringUtils.isNotEmpty(customerVo.getSubmodule())){
            wrapper.like("submodule",customerVo.getSubmodule());
        }

        if (StringUtils.isNotEmpty(customerVo.getQuestion())){
            wrapper.like("question",customerVo.getQuestion());
        }

        Page<TbCustomerIssues> page1 = customerMapper.selectPage(page, wrapper);
        return RR.ok().put("records",page1.getRecords()).put("total",page1.getTotal());




    }

    @Override
    public RR insert(TbCustomerIssues tbCustomerIssues) {
        int i=customerMapper.insert(tbCustomerIssues);
        return RR.ok();
    }

    @Override
    public RR update(TbCustomerIssues tbCustomerIssues) {
        int update = customerMapper.updateById(tbCustomerIssues);
        return RR.ok();
    }

    @Override//根据id回显
    public RR selectById(Integer id) {
        TbCustomerIssues tbCustomerIssues=customerMapper.selectById(id);
        return RR.ok().put("huixian",tbCustomerIssues);
    }

    @Override
    public RR delete(Integer id) {
         int i = customerMapper.deleteById(id);
        return RR.ok();
    }
}
